package client;

import server.core.AbstractSend2Data;
import server.core.AbstractSenderFactory;
import server.core.IGetDeviceInfo;
import server.core.tcp.TcpSenderFactory;

/**
 * describe:所有类型的设备下发流程.
 * 1.到 redis 查找设备信息
 * 2.调用 sendData() 接口，
 * 3.响应调用者
 *
 * @author helloworldyu
 * @data 2018/1/22
 */
public class SendDataService {
	private AbstractSenderFactory factory;

	public SendDataService(AbstractSenderFactory factory) {
		this.factory = factory;
	}

	public static void main(String[] args) {
		TcpSenderFactory factory = new TcpSenderFactory();
		SendDataService sendDataService = new SendDataService(factory);
		sendDataService.service("common");
	}

	public void service(String condition ){
		//===========设备信息查找==========
		IGetDeviceInfo deviceInfoer = factory.createDeviceInfoer(condition);
		String deviceIndo = deviceInfoer.getDeviceIndo();
		System.out.println("获取到设备信息: "+deviceIndo);
		//===========消息发送者============
		AbstractSend2Data sender = factory.createSender(condition);
		String result = sender.sendData();
		//==========响应调用者=============
		System.out.println("响应调用者  "+result);
	}
}